package tree.递归;

import po.TreeNode;

/**
 * @author songZiHao
 * @version 1.0.0
 * @ClassName 合并二叉树617.java
 * @Description https://leetcode-cn.com/problems/merge-two-binary-trees/
 * @createTime 2021年06月22日 19:40:00
 */
public class 合并二叉树617 {
    public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {
        if (root1 == null) {
            return root2;
        }
        if (root2 == null) {
            return root1;
        }
        TreeNode treeNode=new TreeNode();
        treeNode.val=root1.val+root2.val;
        treeNode.left=mergeTrees(root1.left,root2.left);
        treeNode.right=mergeTrees(root1.right,root2.right);
        return treeNode;
    }

}
